<template>
  <div class="advance-table-body">
    <!--搜索栏-->
    <el-form class="search-form--inset" ref="elForm" :model="queryParams" inline size="small" label-width="100px" label-position="left">
      <el-form-item label="用户ID">
        <el-input v-model="queryParams.userId" placeholder="请输入" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="订单号">
        <el-input v-model="queryParams.seqNo" placeholder="请输入" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="支付方式">
        <el-select v-model="queryParams.paymentType">
          <el-option label="支付宝" value="01"></el-option>
          <el-option label="微信" value="02"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="注册时间">
        <el-date-picker
          v-model="zcTime"
          @change="changeTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <trust-query-filter-operation :searchAdvanced.sync="searchAdvanced" @query="searchAction" @reset="resetAction"></trust-query-filter-operation>
    </el-form>
    <!--操作栏-->
    <div class="table-operator">
      <el-button type="primary" size="small" plain @click="clickBtnExport">导出</el-button>
    </div>
    <!--表格-->
    <el-table
      class="k-table"
      ref="table"
      @selection-change="handleSelectionChange"
      :data="tableList"
      v-loading="loading"
      show-summary
      :summary-method="getSummaries"
    >
      <!--<el-table-column label="多选" type="selection" align="center" fixed width="50" />-->
      <el-table-column label="NO" type="index" :formatter="fIndex" align="center" fixed width="80" />
      <el-table-column label="用户ID" fixed align="left" prop="id" show-overflow-tooltip min-width="120" />
      <el-table-column label="用户账号" align="left" prop="userName" min-width="100px" show-overflow-tooltip />
      <el-table-column label="订单号" align="left" prop="seqNo" show-overflow-tooltip min-width="100"/>
      <el-table-column label="订单类型" align="left" prop="orderLabel" min-width="100px" show-overflow-tooltip />
      <el-table-column label="订单金额" align="left" prop="amount" min-width="100px" show-overflow-tooltip />
      <el-table-column label="订单点数" align="left" prop="points" min-width="80" show-overflow-tooltip />
      <el-table-column label="支付方式" align="left" prop="paymentTypeLabel" min-width="80" show-overflow-tooltip />
      <el-table-column label="订单状态" align="left" prop="orderStatusLabel" min-width="80" show-overflow-tooltip />
      <el-table-column label="卡密发放渠道" align="left" prop="issueTypeLabel" min-width="80" show-overflow-tooltip />
      <el-table-column label="卡密发放状态" align="left" prop="issueStatusLabel" min-width="80" show-overflow-tooltip />
      <el-table-column label="卡密充值状态" align="left" prop="chargeStatusLabel" min-width="80" show-overflow-tooltip />
      <el-table-column label="创建时间" align="left" prop="createTime" min-width="80" show-overflow-tooltip />
      <!--<el-table-column label="操作" align="left" width="150" fixed="right">-->
      <!--  <template #default="{ row }">-->
          <!--<el-button type="text" @click="clickBtnEditRule(row)">{{flag(row)?"编辑规则":"配置规则"}}</el-button>-->
      <!--  </template>-->
      <!--</el-table-column>-->
    </el-table>
    <trust-pagination
      :total="total"
      :page-size.sync="queryParams.pageSize"
      :current-page.sync="queryParams.pageNum"
      @size-change="handleSizeChange" @current-change="handleCurrentChange"></trust-pagination>
  </div>
</template>

<script>
import { saTableMixin } from '@/views/custom/mixin/saTableMixin';
import zDate from '@/views/custom/tool/z-date';

export default {
  name: "orderList",
  components: {  },
  mixins: [saTableMixin],
  data() {
    return {
      rules: [],
      options: [],
      zcTime:null,
    }
  },
  mounted() {
    this.requestData("order_info/list","get",this.queryParams);
  },
  methods:{
    clickBtnExport(){
      this.download('order_info/export', {}, `订单列表${new Date().getTime()}.xlsx`)
    },
    changeTime(val){
      this.queryParams.startTime = zDate.timeDateToString(val[0]);
      this.queryParams.endTime = zDate.timeDateToString(val[1]);
    },
    getSummaries(param){
      const { columns, data } = param;
      const sums = [];
      // console.log("=====",param);
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        if (column.property === "amount"||column.property === "points"){
          const values = data.map(item => Number(item[column.property]));
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += '';
        }else {
          sums[index] = '';
        }
      });
      return sums;
    }
  }
}

</script>
